
#ifndef _CORDLESS_MAIN_H_
#define _CORDLESS_MAIN_H_

#include "sys_config.h"
#include "sys_types.h"
#include "host_types.h"
#include "cordless.h"

void CordlessMain_Initialise(void);
u_int8 CordlessMain_Sched(void);
void CordlessMain_TacticalConnect(void * dummy);
void CordlessMain_Audio_Connect_Complete(t_bdaddr* ag_bdaddr, u_int16 sco_handle,u_int8 status);
void CordlessMain_Audio_Disconnect_Complete(u_int16 scoHandle, u_int8 status);
void CordlessMain_LOAD_Address(t_bdaddr* bdAddress,u_int8 type);
void CordlessMain_CellConnectedSuccessful(t_bdaddr ag_bdaddr);
void CordlessMain_CellReleasedInd();
u_int8 CordlessMain_Address_Exist(t_bdaddr bdAddress);
void CordlessMain_TacticalConnect(void * dummy);
void CordlessMain_UnReasonableDisconnectIndication(t_bd_addr bdAddress);

#define MAX_CORDLESS_APP_DEVICE_SUPPORT 7
#define CORDLESS_APP_VERSION 1

//state
#define CORDLESS_NOT_CONNECT 0
#define CORDLESS_TL_CONNECTED_IDLE 0x1
#define CORDLESS_GW_CONNECTED 0x2
#define CORDLESS_BUSY 0x3

#define CORDLESS_TL_OUTGOING_CALL_SETUP_PANDING 0x10
#define CORDLESS_TL_OUTGOING_CALL_SETUP_SUCCESSFUL 0x11
#define CORDLESS_TL_OUTGOING_CALL_CONNECTED2REMOTE 0x12
#define CORDLESS_TL_OUTGOING_CALL_ACTIVE 0x13
#define CORDLESS_TL_OUTGOING_CALL_RELEASE_PANDING 0x14
#define CORDLESS_TL_INCOMING_CALL4PICK_UP 0x15
#define CORDLESS_TL_INCOMING_CALL_CONNECTING 0x16
#define CORDLESS_TL_INCOMING_CALL_CONNECTING2 0x17
#define CORDLESS_TL_INCOMING_CALL_ACTIVE 0x18
#define CORDLESS_TL_INCOMING_CALL_RELEASE_PANDING 0x19

#define CORDLESS_TL_INTERCOM_INITIAL 0x20
#define CORDLESS_TL_INTERCOM_SETUP_PANDING 0x21
#define CORDLESS_TL_INTERCOM_CONNECTED2REMOTE 0x22
#define CORDLESS_TL_INTERCOM_ACTIVE 0x23
#define CORDLESS_TL_INTERCOM_RELEASE_PANDING 0x24
#define CORDLESS_TL_RECEIVING_INTERCOM_CONNECT 0x25
#define CORDLESS_TL_RECEIVING_INTERCOM4PICK_UP 0x26
#define CORDLESS_TL_RECEIVING_INTERCOM_CONNECTING 0x27
#define CORDLESS_TL_RECEIVING_INTERCOM_CONNECTING2 0x28

#define CORDLESS_TWO_WAY_RADIO_DISABLE 0x30
#define CORDLESS_TWO_WAY_RDAIO_CONNECTING 0x31
#define CORDLESS_TWO_WAY_RDAIO_VOICE_ESTABLISH 0x32
#define CORDLESS_TWO_WAY_RDAIO_ACTIVE 0x33

#define CORDLESS_MONITOR_CONNECTING 0x40
#define CORDLESS_MONITOR_VOICE_ESTABLISH 0x41
#define CORDLESS_MONITOR_ACTIVE 0x42

#define CORDLESS_GW_INCOMING_CALL_ACTIVE 0xf0
#define CORDLESS_GW_INCOMING_CALL_CONNECTING 0xf1
#define CORDLESS_GW_INCOMING_CALL_WAIT_ONE4PICK_UP 0xf2
#define CORDLESS_GW_OUTGOING_CALL_RELEASE_PANDING 0xf3
#define CORDLESS_GW_OUTGOING_CALL_ACTIVE 0xf4
#define CORDLESS_GW_OUTGOING_CALL_CONNECTED2REMOTE 0xf5
#define CORDLESS_GW_OUTGOING_CALL_CONNECTING 0xf6
#define CORDLESS_GW_OUTGOING_CALL_WAIT4EXTERN_PICK_UP 0xf7
#define CORDLESS_GW_OUTGOING_CALL_SETUP_PANDING 0xf8

#define CORDLESS_CELL_NOT_USING 0
#define CORDLESS_CELL_ENABLE 1
#define CORDLESS_CELL_CONNECTING2CELL 2
#define CORDLESS_CELL_CONNECTSUCCESSFUL 3
#define CORDLESS_CELL_CALL_ACTIVE 4

#define CORDLESS_ADDRESS_TYPE_GW 0
#define CORDLESS_ADDRESS_TYPE_CELL 1
#define CORDLESS_ADDRESS_TYPE_TL 2

#define CORDLESS_APP_PEER_DEVICE_NOT_USING 0
#define CORDLESS_APP_PEER_DEVICE_GW_CONNECTING 1
#define CORDLESS_APP_PEER_DEVICE_TL_CONNECTING 2
#define CORDLESS_APP_PEER_DEVICE_TL_REGIST_NOT_CONNECTING 3
//end of state

//phone state
#define CORDLESS_PHONE_OFF	0
#define CORDLESS_PHONE_ON		1
//end of phone state

struct t_Cordless_App_Peer_Device
{
	t_bdaddr bdAddress;
	u_int8 state;
	u_int8 version;
	u_int8 name[20];
	u_int8 name_length;
	u_int16 psm;
	u_int16 ACLHandle;
};

struct t_Cordless_Calling_Peer_Device
{
	u_int8 using_device;
	u_int16 callHandle;
	u_int16 callType;
	u_int16 sco_handle;
};

struct t_Cordless_Cell_Device
{
	u_int8 CellState;
	t_bdaddr CellAddress;
	u_int16 sco_handle;
};

struct t_Cordless_Time
{
	u_int32 year:6;
	u_int32 month:4;
	u_int32 day:5;
	u_int32 hour:5;
	u_int32 minute:6;
	u_int32 second:6;
	u_int8 weekday;
};

struct t_Cordless_Menu
{
	u_int8 menu_enable;
	u_int32 menu_level;
	u_int32 menu_focus;
};

struct t_Cordless_Device
{
	u_int8 state;
	u_int8 phone_state;
	struct t_Cordless_Time Cordless_Time;
	struct t_Cordless_Calling_Peer_Device Cordless_Calling_Dev; 
	struct t_Cordless_App_Peer_Device Cordless_App_Dev[MAX_CORDLESS_APP_DEVICE_SUPPORT];
	struct t_Cordless_Menu Cordless_Menu;
};

#endif
